package com.mtzqc.common.img.engine

import android.net.Uri
import androidx.fragment.app.Fragment
import com.luck.picture.lib.engine.CropFileEngine
import com.yalantis.ucrop.UCrop


class UCropEngineImpl(
    var block: UCrop.Options.() -> Unit = {
        withAspectRatio(1f, 1f)
    }
) : CropFileEngine {
    override fun onStartCrop(
        fragment: Fragment,
        srcUri: Uri,
        destinationUri: Uri,
        dataSource: ArrayList<String>,
        requestCode: Int
    ) {
        val options = UCrop.Options();
        options.setHideBottomControls(true)
        block.invoke(options)
        val uCrop = UCrop.of(srcUri, destinationUri, dataSource)
        uCrop.withOptions(options)
        uCrop.setImageEngine(Engine.uCropImageEngine())
        uCrop.start(fragment.requireActivity(), fragment, requestCode)
    }
}